package concurrency.basicthreading.demo;

public class Demo12Sleeper extends Thread {

	private int duration;
	public Demo12Sleeper(String name, int sleepTime) {
		super(name);
		duration = sleepTime;
		start();
	}
	
	@Override
	public void run() {
		try {
			
			/*
			 * sleep()有可在执行期间能被中断, catch将根据isInterrupted()方法的返回值来报告这个中断。当我们在主线程(main)中调用interrupt()
			 * 方法时将给该线程设定一个标志, 表明该线程以被中断。然而异常捕获时将清理这个标志，所以在catch语句中，在异常被捕获时这个
			 * 标志总是为假。除异常之外(即非手动中断)
			 */

			sleep(duration);
		}catch (InterruptedException e) {
			System.out.println(getName() + " was interrupted. is Interrupted() : " + isInterrupted());
			return;
		}
		System.out.println(getName() + " has awakened");
	}	
}
